using System;
using System.Collections.Generic;
using System.Text;

namespace GetTogether.Studio.Profile
{
    public class Util
    {
        public static string Sign(SessionObjects sess, string username, string password)
        {
            try
            {
                string profileFile = string.Concat(Config.GetIncludeFolder(), "\\Profile\\Signs.config");
                string xml = System.IO.File.ReadAllText(profileFile, System.Text.Encoding.UTF8);
                Profile.Signs signs = GetTogether.Utility.SerializationHelper.FromXml<Profile.Signs>(xml);
                if (signs == null || signs.Items == null || signs.Items.Length == 0) return "Not signs found";
                foreach (Profile.SignsSign ss in signs.Items)
                {
                    if (ss.Username == username && ss.Password == password)
                    {
                        sess.SignUsername = username;
                        sess.SignPassword = password;
                        sess.UserCode = username;
                        return string.Empty;
                    }
                }
                return "Invalid password or username";
            }
            catch (Exception ex)
            {
                Log.Error(ex);
                return ex.Message;
            }
        }
    }
}
